class SurpriseScene extends Scene {
  private searchText:eui.EditableText;
  private searchImage:eui.Image;
  private surpriseList:eui.List;
  private returnImage :eui.Image;
  public static instance: SurpriseScene;
	private surprisreScroller:eui.Scroller;
	private surpriserArr:any  = [];
	private needUp: boolean = false;
 // private needDown: boolean = false;
  private scrollerBar:eui.VScrollBar;
  private moreImage : eui.Label;

  public constructor() {
    super();
    SurpriseScene.instance = this;
    this.addEventListener(egret.Event.COMPLETE, this.addToStage, this);
  }

  public onSkinLoaded() {
        //this.surprisreScroller.addEventListener(egret.Event.CHANGE, this.onScrollerChange, this);
        this.searchImage.addEventListener(egret.TouchEvent.TOUCH_TAP, this.btnHandler, this);
        this.returnImage.addEventListener(egret.TouchEvent.TOUCH_TAP, this.btnHandler, this);
}

private addToStage():void{
  console.log("LLLLL");
  this.moreImage.visible=false;
  for(var i:number=1;i<=6;i++){
    this.surpriserArr.push({biglabelText:"big",smalllabelText:"small"});
  }
  this.surpriseList.dataProvider=new eui.ArrayCollection(this.surpriserArr);
  this.surpriseList.itemRenderer=SurpriseRenderer;
  this.surprisreScroller.addEventListener(eui.UIEvent.CHANGE, this.moveHandler, this);
	this.surprisreScroller.addEventListener(eui.UIEvent.CHANGE_END, this.outHandler, this);
}



  private btnHandler(evt: egret.TouchEvent) {
    let btnFocused = evt.currentTarget;
  switch (btnFocused) {
    case this.searchImage:
        console.log(this.label);
        break;
    case this.returnImage:
        //SceneManager.instance.removeScene(this.scroller_page);
        SceneManager.instance.removeScene(this);
         break;    
    }
  }

  public get label():string{
    return this.searchText.text;
  }    

	protected createChilden(){
		super.createChildren();
  }

  
	
	private moveHandler(evt: eui.UIEvent): void {
		//检测是否超过滚动底部
		// console.log(this.moveScroll.viewport.scrollV);
		// console.log(this.moveScroll.viewport.contentHeight - this.moveScroll.viewport.height);
		console.log(this.surprisreScroller.viewport.scrollV > this.surprisreScroller.viewport.contentHeight - this.surprisreScroller.viewport.height);
		if(this.surprisreScroller.viewport.scrollV > (this.surprisreScroller.viewport.contentHeight - this.surprisreScroller.viewport.height)+40){
      this.needUp = true;
      this.moreImage.visible=true;
     }
  }
	private outHandler(evt:eui.UIEvent):void{
		//停止滚动时判断needUp是否为true
		if(this.needUp){
			this.needUp = false;
      this.addToStage();
		}
  }

 /* private onScrollerChange() {
    let scrollV = this.surprisreScroller.viewport.scrollV;
    let thumbY = Math.abs(scrollV) / (this.surprisreScroller.viewport.measuredHeight - this.surprisreScroller.height);
    this.scrollerBar.thumb.y = thumbY * (this.scrollerBar.height - this.scrollerBar.thumb.height);
    console.log(this.scrollerBar.thumb.height);
  }
  */
}

